    <div class="main-content">
    	<div class="breadcrumbs" id="breadcrumbs">
			<script type="text/javascript">
				try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
				$(document).ready(function () {
					getTree();
				 });
			</script>
		</div>

        <!-- Main content -->
        <div class="page-content">
			<div class="page-header">
				<h1>系统用户</h1>
			</div>
			<div class="row">
            
				<div>
				<div class="col-xs-12">
					<a href="<?php echo base_url().'admin/systems/add_user';?>" class="btn btn-info btn-sm"><i class="icon-copy"></i>新增</a>
					<a href="javascript:void(0)" onclick="delSomeModal()" data-toggle="modal" class="btn btn-danger btn-sm"><i class="icon-trash"></i>删除</a>
				</div>
				<br><br>
				<div class="col-xs-12">
				    <form action="<?php echo base_url().'admin/systems/query_user';?>" method="get">
				        <div class="col-xs-3">
                            <label style="display: inline-block;width:40%;">用户名：</label>
                            <input name="login_name" style="display: inline-block;width:50%;" value="<?php echo $login_name; ?>" type="text" class="form-control">
                        </div>
                        <div class="col-xs-3">
                            <label style="display: inline-block;width:40%;">姓名：</label>
                            <input name="user_name" style="display: inline-block;width:50%;" value="<?php echo $user_name; ?>" type="text" class="form-control">
                        </div>
                        <div class="col-xs-3">
                            <label style="display: inline-block;width:40%;">角色：</label>
                            <select style="display: inline-block;width:50%;" class="form-control" id="role_id" name="role_id">
                                <option value="">全部</option>
                                <?php foreach ($user_role as $key=>$val){?>
            					<option value="<?php echo $key;?>" <?php if ($role_id == $key) echo "selected"; ?>><?php echo $val?></option>
            					<?php }?>
                            </select>
                        </div>
                        <input type="hidden" name="department_id" value=<?php echo isset($department_id)?$department_id:0;?>>
                        <button id="btnSubmit" type="submit" class="btn btn-info btn-sm"><i class="icon-search"></i>查询</button>
				    </form>
				</div>
				<br>
	            <div class="col-xs-12">
	                <div class="table-responsive">
	                <input type="hidden" name="upid" id="upid" value=""/>
	                <form action="<?php echo base_url()."admin/systems/del_some_user"?>" method="post" id="delForm">
                        <table class="table table-striped table-bordered">
                            <thead>
                            <tr>
                            	<th class="center" style="width: 3%">
	                            	<label>
										<input type="checkbox" class="ace" />
										<span class="lbl"></span>
									</label>
                            	</th>
                            	<th>用户名</th>
                                <th>用户姓名</th>
                                <th>手机号码</th>
                               
                                <th>用户角色</th>
                              
                                <th>最近登录时间</th>
                                <th style="width: 25%;">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php if (isset($result)&&count($result)>0){
                            	foreach ($result as $user){
                            	?>
                            <tr>
                            	<td class="center">
                            		<label>
										<input type="checkbox" class="ace" name="num[]" value="<?php echo $user->id;?>"/>
										<span class="lbl"></span>
									</label>
                            	</td>
                            	<td><?php echo $user->login_name;?></td>
                            	<td><?php echo $user->user_name;?></td>
                            	<td><?php echo $user->user_phone;?></td>
                            	
                            	<td><?php echo $user->role_name;?></td>
                            	
                            	<td><?php echo $user->last_login_time;?></td>
                            	<td>
                            	    <a href="javascript:void(0)" onclick="uppwd('<?php echo $user->id;?>')" data-toggle="modal" class="btn btn-warning btn-sm">重置密码</a>
	                            	<a href="<?php echo base_url().'admin/systems/edit_user/'.$user->id;?>" class="btn btn-info btn-sm"><i class="icon-edit"></i>修改</a>
	                            	<?php if ($user->id!='1'){?>
	                            	<a href="javascript:void(0)" onclick="delmodal('<?php echo $user->id;?>')" data-toggle="modal" class="btn btn-danger btn-sm"><i class="icon-trash"></i>删除</a>
	                            	<?php }?>
                            	</td>
                            </tr>
                            <?php }
                            }else{?>
                            <tr>
                            	<td colspan="9">无数据</td>
                            </tr>
                            <?php }?>
                            </tbody>
                         </table>
                         </form>
                    </div><!-- /.table-responsive -->
                    <div class="modal-footer no-margin-top">
	                	<div class="pull-left record">
							共<?php echo $count;?>条记录
	                    </div>
                		<?php if (isset($page))echo $page;?>
                	</div>
	            </div>
	            </div>
	        </div>
       	</div> <!--  /.page-content -->
    </div><!-- /.main-content -->
	<div id="delModal" class="modal fade" role="dialog" aria-hidden="true">
		<div class="modal-dialog" style="width: 300px">
			<div class="modal-content">
				<div class="modal-header">
				  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				  <h3>提示信息</h3>
				</div>
				<div class="modal-body">
				  <p>删除后用户将无法使用，确定要删除吗？</p>
				</div>
				<div class="modal-footer">
				  <a id="delbtn" href="#" class="btn btn-danger">确定</a>
				  <a href="#" class="btn btn-info" data-dismiss="modal" aria-hidden="true">取消</a>
				</div>
			</div>
		</div>
	</div>
	
	<div id="delsomeModal" class="modal fade" role="dialog" aria-hidden="true">
		<div class="modal-dialog" style="width: 300px">
			<div class="modal-content">
				<div class="modal-header">
				  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				  <h3>提示信息</h3>
				</div>
				<div class="modal-body">
				  <p>确定要删除所选用户吗？</p>
				</div>
				<div class="modal-footer">
				  <button id="delsomebtn" type="submit" class="btn btn-danger">确定</button>
				  <a href="#" class="btn btn-info" data-dismiss="modal" aria-hidden="true">取消</a>
				</div>
			</div>
		</div>
	</div>
	
	<div id="upModal" class="modal fade" role="dialog" aria-hidden="true">
		<div class="modal-dialog" style="width: 300px">
			<div class="modal-content">
				<div class="modal-header">
				  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				  <h3>提示信息</h3>
				</div>
				<div class="modal-body">
				  <p>确定要重置密码吗？</p>
				</div>
				<div class="modal-footer">
				  <a id="upbtn" href="#" onclick="showpwd()" class="btn btn-danger">确定</a>
				  <a href="#" class="btn btn-info" data-dismiss="modal" aria-hidden="true">取消</a>
				</div>
			</div>
		</div>
	</div>
	
	<div id="adddepartment" class="modal fade" role="dialog" aria-hidden="true">
		<div class="modal-dialog" style="width: 650px;height: 500px;">
			<div class="modal-content">
				<div class="modal-header">
				  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				  <h3>添加部门</h3>
				</div>
				<form action="<?php echo base_url()."admin/systems/add_department"?>" method="post" id="add_depart">
				<div class="modal-body" style="height: 200px;">
				
			        <div class="col-xs-6">
                        <label style="display: inline-block;width:30%;">部门名称：</label>
                        <input id="depart_name" name="name" style="display: inline-block;width:50%;" value="" type="text" class="form-control">
                    </div>
                    <div class="col-xs-6">
                        <label style="display: inline-block;width:40%;">是否为公司：</label>
                        <select name="is_company" class="form-control" style="display: inline-block;width:50%;">
                        	<option value="0">否</option>
                        	
                            <option value="1">是</option>
                        </select>
                    </div>
                
                    <br><br>
                    
                    <div class="col-xs-6">
                        <label style="width:30%;">上级部门：</label>
                        <select name="parent_id" class="form-control" style="display: inline-block;width:50%;">
                        	<option value="<?php echo $_SESSION['DEPARTMENT_ID']?>">无上级部门</option>
                        	<?php if (isset($department)&&count($department)>0){
                            	foreach ($department as $val){?>
                            <option value="<?php echo $val->id?>" <?php if ($val->id==set_value("parent_id")){?>selected<?php }?>><?php echo $val->text?></option>
                            <?php }
                            	}?>
                        </select>
                    </div>
                    <div class="col-xs-10">
                        <label style="display: inline-block;width:14%;">备注：</label>
                        <textarea rows="3" cols="70" name="note"></textarea>
                    </div>
				</div>
				<div class="modal-footer">
				  <button type="button" class="btn btn-info" id="add_btn">确定</button>
				  <a href="#" class="btn btn-danger" data-dismiss="modal" aria-hidden="true">取消</a>
				</div>
				</form>
			</div>
		</div>
	</div>
	
	<script type="text/javascript">
	$("#add_btn").on('click',function(event){
		// 2.最后要调用 valid()方法。
		if ($('#depart_name').val() == ''){
			alert('请填写正确的部门名称');
		}else{
			$("#add_depart").submit();
		}
	});
	function delmodal(id){
		$("#delbtn").attr('href','<?php echo base_url().'admin/systems/del_user/'?>'+id);
	    $('#delModal').modal('show');
	}
	function uppwd(id){
	    $('#upModal').modal('show');
	    $('#upid').val(id);
	}
	function showpwd(){
		$('#upModal').modal('hide');
		showLoading('重置中');
		$.ajax({  
            type:'POST',  
            url:'<?php echo base_url().'admin/systems/up_pwd'?>',  
            data:{  
                id:$('#upid').val()
            },  
            dataType:'json',  
            success:function(data){
                if(data.code == "200"){
                    alert("密码重置成功，新密码为123456。");
                    
                }else{
                    alert("密码重置失败。");
                    
                }
                hideLoading();
            }
		})
	}
	function getTree(){
		$.ajax( {
	        url:'<?php echo base_url().'admin/systems/department';?>',
	        data:{'department_id':'<?php echo $department_id;?>'},
	        type:'post',
	        cache:false,
	        dataType:'json',
	        success:function(data) {
	        	$('#tree').treeview({
	            	data: data,
	            	emptyIcon: '',
	            	onNodeSelected:function(event, note){
	            		show_user(note.id);
	            	}
	        	});
	        	$('#tree').treeview('expandAll', {silent:true});
	        },
	        error : function() { 
				alert("error");    
	        }
		});
	}
	function delSomeModal(){
		if(checkSelect()){
	    	$('#delsomeModal').modal('show');
		}else{
			alert('请选择正确的记录进行删除');
		}
	}
	$("#delsomebtn").click(function(){
		$("#delForm").submit();
    });
	function addDp(){
	    $('#adddepartment').modal('show');
	}
	function show_user(id){
		window.location.href="<?php echo base_url().'admin/systems/query_user?role_id=&login_name=&user_name=&department_id='?>"+id;
	}
	</script>
